using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Services;

namespace MainGame.Menu
{

  public interface IHelpMenu
  {
    event MenuEvent OnHBackClicked;
  }

  public class HelpMenu : BaseMenu, IHelpMenu
  {

    Button helpBackBtn;
    Vector2 savedPos;
    public bool Animated = false;
    public int Direction = 1;

    public HelpMenu(Game game, MenuDepths depth)
      : base(game, depth)
    {
      background = game.Content.Load<Texture2D>(@"Images//Menu//Help");
      bounds = new Rectangle(-game.GraphicsDevice.Viewport.Width, 0, game.GraphicsDevice.Viewport.Width, game.GraphicsDevice.Viewport.Height);
      game.Services.AddService(typeof(IHelpMenu), this);
    }

    protected override void Dispose(bool disposing)
    {
      Game.Services.RemoveService(typeof(IHelpMenu));
      base.Dispose(disposing);
    }


    public override void Initialize()
    {
      savedPos.X = bounds.X;
      // Load all buttons
      Color color = Color.Violet;
      color.A = 150;

      Color color2 = Color.Red;
      color2.A = 200;

      helpBackBtn = new Button(Game, @"Images//Menu//button_play", new Rectangle((int)bounds.X + 600, 410, 140, 25), color, "large_font", "Back", color2);
      AddButton(helpBackBtn, () =>
      {
        Animated = true;
        Direction = -1;
      });

      base.Initialize();
    }

    public override void Update(GameTime gameTime)
    {
      
      if (Animated)
      {

        bounds.X += Direction * 35;

        foreach (Button b in (from cb in buttons select cb.b))
        {
          b.bounds.X += Direction * 35;
        }

        if (bounds.X > 0 && Direction == 1)
        {
          Animated = false;
          int offset = bounds.X ;
          bounds.X = 0;

          foreach (Button b in (from cb in buttons select cb.b))
          {
            b.bounds.X += -Direction * offset;
          }

          
        }

        if (bounds.X < savedPos.X)
        {
         
            if (OnHBackClicked != null)
              OnHBackClicked();
          
        }

      }


      base.Update(gameTime);
    }

    public event MenuEvent OnHBackClicked;
  }
}
